package com.fuyao.cloud.personnel.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyao.cloud.common.core.util.R;
import com.fuyao.cloud.common.excel.annotation.ResponseExcel;
import com.fuyao.cloud.common.log.annotation.SysLog;
import com.fuyao.cloud.personnel.api.entity.AccountDisciplinaryRecords;
import com.fuyao.cloud.personnel.service.AccountDisciplinaryRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/accountdisciplinaryrecords" )
@Api(value = "accountdisciplinaryrecords", tags = "处分记录表")
public class AccountDisciplinaryRecordsController {

    private final AccountDisciplinaryRecordsService accountDisciplinaryRecordsService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param accountDisciplinaryRecords 问题管理
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('account_disciplinary_records_view')" )
    public R getAccountDisciplinaryRecordsPage(Page page, AccountDisciplinaryRecords accountDisciplinaryRecords) {
        return R.ok(accountDisciplinaryRecordsService.page(page, Wrappers.query(accountDisciplinaryRecords)));
    }


    /**
     * 通过id查询问题管理
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('account_disciplinary_records_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(accountDisciplinaryRecordsService.getById(id));
    }

    /**
     * 新增问题管理
     * @param accountDisciplinaryRecords 问题管理
     * @return R
     */
    @ApiOperation(value = "新增问题管理", notes = "新增问题管理")
    @SysLog("新增问题管理" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('account_disciplinary_records_add')" )
    public R save(@RequestBody AccountDisciplinaryRecords accountDisciplinaryRecords) {
        return R.ok(accountDisciplinaryRecordsService.save(accountDisciplinaryRecords));
    }

    /**
     * 修改问题管理
     * @param accountDisciplinaryRecords 问题管理
     * @return R
     */
    @ApiOperation(value = "修改问题管理", notes = "修改问题管理")
    @SysLog("修改问题管理" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('account_disciplinary_records_edit')" )
    public R updateById(@RequestBody AccountDisciplinaryRecords accountDisciplinaryRecords) {
        return R.ok(accountDisciplinaryRecordsService.updateById(accountDisciplinaryRecords));
    }

    /**
     * 通过id删除问题管理
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除问题管理", notes = "通过id删除问题管理")
    @SysLog("通过id删除问题管理" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('account_disciplinary_records_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(accountDisciplinaryRecordsService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param accountDisciplinaryRecords 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('account_disciplinary_records_export')" )
    public List<AccountDisciplinaryRecords> export(AccountDisciplinaryRecords accountDisciplinaryRecords) {
        return accountDisciplinaryRecordsService.list(Wrappers.query(accountDisciplinaryRecords));
    }
}

